package cn.xxstudy.blog.config

import cn.xxstudy.blog.util.logger
import org.springframework.context.annotation.Configuration
import org.springframework.web.servlet.config.annotation.InterceptorRegistry
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer

/**
 * 作者：wuxinxi on 2020/11/26
 * 包名：cn.xxstudy.blog.config
 * TODO:全局配置
 */
@Configuration
class GlobalConfig : WebMvcConfigurer {

    /**
     * 拦截器
     */
    override fun addInterceptors(registry: InterceptorRegistry) {
        registry.addInterceptor(LoginInterceptor())
                .addPathPatterns("/admin/**")
                .excludePathPatterns("/admin")
                .excludePathPatterns("/admin/login")
        super.addInterceptors(registry)
    }

    /**
     * 解决图片上传不实时生效的问题
     */
    override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
        val path = System.getProperty("user.dir") + "\\src\\main\\resources\\static\\upload\\"
        registry.addResourceHandler("/upload/**").addResourceLocations("file:$path")
    }
}